package org.jeecg.modules.mail.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.mail.service.IMailService;
import org.jeecg.modules.mail.entity.Mail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;

@Api(tags = "邮件接口")
@RestController
@RequestMapping("/mail/")
@Slf4j
public class MailController{


    @Autowired
    private IMailService iMailService;

    /**
     * 发送邮件
     * @param mail 邮件内容
     * @return
     */
    @ApiOperation("发送邮件")
    @PostMapping("send")
    public Result sendMail(@RequestBody Mail mail){
        iMailService.send(mail);
        return Result.OK();
    }

    /**
     * 发送验证码
     * @param email 发送邮箱
     * @return
     */
    @ApiOperation("向指定邮箱发送验证码")
    @PostMapping("getVerificationCode")
    public Result getVerificationCode(@RequestBody String email) throws MessagingException {
        iMailService.sendVerificationCode(email);
        return Result.OK();
    }

}
